package com.aboo.service;

import com.aboo.api.CompanyService;
import com.aboo.domain.Employee;
import org.apache.dubbo.config.annotation.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@Service(group = "enterprise", version = "1.0")
public class ProviderCompany01Service implements CompanyService {

    @Override
    public String callEmployee(String name) {
        return "hello," + name + "!";
    }

    @Override
    public BigDecimal calcMoney(Integer age) {
        return new BigDecimal(age).multiply(new BigDecimal(120));
    }

    @Override
    public List<Employee> getEmployee(int num) {
        List<Employee> result = new ArrayList<>(num);
        for (int i = 0; i < num; i++) {
            Employee employee = new Employee();
            employee.setId(new Long(100 + new Random().nextInt(100)));
            employee.setName("employee" + num);
            employee.setCardNo(String.format("%4d", new Random().nextInt(10000)));
            employee.setAge(20 + new Random().nextInt(15));
            BigDecimal weight = new BigDecimal(50).add(new BigDecimal(0.2 * new Random().nextInt(100)));
            employee.setWeight(weight.setScale(2, RoundingMode.HALF_UP));
            result.add(employee);
        }

        return result;
    }

}
